﻿using NPOI.XSSF.Streaming.Values;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MicroCloud.Tests.DataStruct
{
    public class SingleLinkList<T>
    {
        private Node<T> head;
        public SingleLinkList()
        {
            head = null;
        }

        public Node<T> Head
        {
            get { return head; }
            set { this.head = value; }
        }

        public int Len
        {
            get
            {
                Node<T> p = head;
                int len = 0;
                while (p != null)
                {
                    ++len;
                    p = p.Next;
                }
                return len;

            }
        }

        /// <summary>
        /// 清空操作
        /// </summary>
        public void Clear()
        {
            head = null;
        }

        /// <summary>
        /// 附加操作,线性表未满，将值为item的新元素添加到末尾
        /// </summary>
        /// <param name="item"></param>
        public void Append(T item)
        {
            Node<T> newNode = new Node<T>(item); 
            if (head == null)
            {
                head = newNode;
                return;
            }
            Node<T> node = head;
            while (node.Next != null)
            {
                node = node.Next;
            }
            node.Next = newNode;
        }

    }
}
